package com.yaorange.certificate.controller.wxapi;

import com.yaorange.certificate.bo.RegisterVo;
import com.yaorange.certificate.domain.NjtUserPerfect;
import com.yaorange.certificate.service.INjtUserPerfectService;
import com.yaorange.certificate.service.INjtUserRegisterService;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.core.domain.model.LoginBody;
import com.yaorange.framework.web.service.SysLoginService;
import com.yaorange.system.service.ISysUserService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序api
 *
 * @author coach tam
 * @email 327395128@qq.com
 * @values 坚持灵活 灵活坚持
 * @since 2025/1/16
 */
@RestController
@RequestMapping("/api/user")
public class NjtUserAPI extends BaseController {
    @Autowired
    private INjtUserRegisterService njtUserRegisterService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private SysLoginService loginService;
    @Autowired
    private INjtUserPerfectService perfectService;


    @GetMapping("/sendValidateCode")
    public AjaxResult sendValidateCode(@RequestParam("mobilePhone") String mobilePhone) {
        njtUserRegisterService.sendValidateCode(mobilePhone);
        return AjaxResult.success();
    }
    //http://localhost:8080/api/user/checkMobilePhone?mobilePhone=15700693583
    @GetMapping("/checkMobilePhone")
    public AjaxResult checkMobilePhone(@RequestParam("mobilePhone") String mobilePhone) {
        return AjaxResult.success(njtUserRegisterService.checkMobilePhone(mobilePhone));
    }


//    Request URL:
//    http://localhost:8080/api/user/register
//    Request Method: POST
//{"mobilePhone":"18180692791","password":"static","checkCode":"717080"}
    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterVo registerVo) {
        njtUserRegisterService.register(registerVo);
        return AjaxResult.success();
    }

    //post请求  正文是json 格式:{"username":"18180692791","password":"18180692791"}
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody) {
        String token = loginService.wxLogin(loginBody);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("token", token);
        return ajaxResult;
    }


    @GetMapping("/queryLoginUser")
    public AjaxResult queryLoginUser(){
        return AjaxResult.success(njtUserRegisterService.queryLoginUser());
    }


    @PostMapping("/perfect")
    public AjaxResult perfect(@RequestBody NjtUserPerfect perfect) {
        perfectService.perfect(perfect);
        return AjaxResult.success();
    }


}
